import { createBrowserRouter, Navigate } from 'react-router-dom';
import React from 'react';

const AuthComponent = props => {
    const Com = props.children.type
    if (sessionStorage.getItem('accesstoken')) {
        return <Com />
    } else {
        if (localStorage.getItem('user')) {
            return <Navigate to='/reallogin'></Navigate>
        } else {
            return <Navigate to='/mima'></Navigate>
        }
    }
}
    const App = React.lazy(() => import('../App'))

    //刘玉辉
    const Home = React.lazy(() => import('../views/Home/Home'))
    const My = React.lazy(() => import('../views/My/My'))
    const Piao = React.lazy(() => import('../views/Piao/Piao'))
    const Type = React.lazy(() => import('../views/Type/Type'))
    const Message = React.lazy(() => import('../views/Message/Message'))
    const Login = React.lazy(() => import('../views/Login/Login'))
    const Phone = React.lazy(() => import('../views/Login/Phone'))
    const Mima = React.lazy(() => import('../views/Login/Mima'))
    const Reallogin = React.lazy(() => import('../views/Login/Reallogin'))
    const Showpiao = React.lazy(() => import('../views/Piao/Showpiao'))


// 苗珺朔
// 杨子欣
// 王森


    // 王森
    const Search = React.lazy(() => import('../views/Home/Search/Search'))
    const Xiang = React.lazy(() => import('../views/Home/Xiang/Xiang'))
    const Yi = React.lazy(() => import('../views/Home/Yi/Yi'))


    // 苗珺朔
    const Feedback = React.lazy(() => import('../views/My/Feedback'))
    const Settings = React.lazy(() => import('../views/My/Settings/Settings'))
    const Information = React.lazy(() => import('../views/My/Settings/Information'))
    const Nickname = React.lazy(() => import('../views/My/Settings/Nickname'))
    const Profile = React.lazy(() => import('../views/My/Settings/Profile'))
    const Safe = React.lazy(() => import('../views/My/Settings/Safe/Safe'))
    const Editphone = React.lazy(() => import('../views/My/Settings/Safe/Editphone'))
    const Messages = React.lazy(() => import('../views/My/Settings/Messages'))
    const Address = React.lazy(() => import('../views/My/Settings/Address/Address'))
    const Addressadd = React.lazy(() => import('../views/My/Settings/Address/Addressadd'))
    const Addressedit = React.lazy(() => import('../views/My/Settings/Address/Addressedit'))
    // 杨子欣
    const Txq = React.lazy(() => import('../views/Type/Txq'))
    const Tpl = React.lazy(() => import('../views/Type/Tpl'))
    const Pxq = React.lazy(() => import('../views/Type/Pxq'))
    // 杨泽芃
    const Xzcc = React.lazy(() => import('../views/Type/Xzcc'))
    const Ddjs = React.lazy(() => import('../views/Type/Ddjs'))
    const Syt = React.lazy(() => import('../views/Type/Syt'))
    const Zfcg = React.lazy(() => import('../views/Type/Zfcg'))
    const Cgxq = React.lazy(() => import('../views/Type/Cgxq'))
    // 石永来
    const Xx = React.lazy(() => import('../views/Message/Xx'))
    // 郭方

    const Begin = React.lazy(() => import('../views/My/Begin'))
    const Order = React.lazy(() => import('../views/My/Order'))
    const Fans = React.lazy(() => import('../views/My/Fans'))
    const Quan = React.lazy(() => import('../views/My/Quan'))
    const Guanyan = React.lazy(() => import('../views/My/Guanyan'))
    const Pingjia = React.lazy(() => import('../views/My/Pingjia'))
    const Shoucang = React.lazy(() => import('../views/My/Shoucang'))

    const router = createBrowserRouter(
        [
            {
                path: '/app',
                element: <App></App>,
                children: [
                    {
                        path: '/app',
                        element: <Navigate to='/app/home'></Navigate>
                    },
                    {
                        path: '/app/home',
                        element: <Home />
                    },
                    {
                        path: '/app/piao',
                        element: <AuthComponent><Piao /></AuthComponent>
                    },
                    {
                        path: '/app/type',
                        element: <Type />
                    },
                    {
                        path: '/app/xzcc',
                        element: <Xzcc></Xzcc>
                    },
                    {
                        path: '/app/ddjs',
                        element: <Ddjs></Ddjs>
                    },
                    {
                        path: '/app/syt',
                        element: <Syt></Syt>
                    },
                    {
                        path: '/app/zfcg',
                        element: <Zfcg></Zfcg>
                    },
                    {
                        path: '/app/cgxq',
                        element: <Cgxq></Cgxq>
                    },
                    {
                        path: '/app/message',
                        element: <AuthComponent><Message /></AuthComponent>
                    },
                    {
                        path: '/app/my',
                        element: <AuthComponent><My /></AuthComponent>
                    },
                ]
            },
            {
                path: '/search',
                element: <Search />,
            },
            {
                path: '/xiang',
                element: <Xiang />
            },
            {
                path: '/yi',
                element: <Yi />
            },

            {
                path: '/piao',
                element: <Piao />
            },
            {
                path:'/phone',
                element:<Phone />
            },
            {
                path:'/mima',
                element:<Mima />
            },
            {
                path:'/reallogin',
                element:<Reallogin />
            },
            {
                path: 'showpiao',
                element: <Showpiao />
            },
            {
                path: 'xx',
                element: <Xx />
            },
            {
                path: '/begin',
                element: <Begin />
            },
            {
                path: '/',
                element: <Login></Login>
            },
            {
                path: '/login',
                element: <Login />
            },
            {
                path: '/order',
                element: <Order />
            },
            {
                path: '/fans',
                element: <Fans />
            },
            {
                path: '/quan',
                element: <Quan />
            },
            {
                path: '/guanyan',
                element: <Guanyan />
            },
            {
                path: '/pingjia',
                element: <Pingjia />
            },
            {
                path: '/shoucang',
                element: <Shoucang />
            },

            //苗珺朔
            {
                path: "/settings",
                element: <Settings></Settings>
            },
            {
                path: "/information",
                element: <Information></Information>
            },
            {
                path: "/nickname",
                element: <Nickname></Nickname>
            },
            {
                path: "/profile",
                element: <Profile></Profile>
            },
            {
                path: "/safe",
                element: <Safe></Safe>
            },
            {
                path: "/editphone",
                element: <Editphone></Editphone>
            },
            {
                path: "/messages",
                element: <Messages></Messages>
            },
            {
                path: "/address",
                element: <Address></Address>
            },
            {
                path: "/addressadd",
                element: <Addressadd></Addressadd>
            },
            {
                path: "/addressedit",
                element: <Addressedit></Addressedit>
            },
            {
                path: '/txq',
                element: <Txq></Txq>
            },
            {
                path: '/tpl',
                element: <Tpl></Tpl>
            },

            {
                path: '/pxq',
                element: <Pxq></Pxq>
            }

        ]
    );



//抛出对象
export default router;
